<template>
  <el-container>
    <el-header>
      <div class="header-left">
        <div>
          <span v-if="isCollapse" class="el-icon-eleme header-logo"></span>
          <span v-else class="header-title">电商后台管理系统</span>
        </div>
        <span class="change-btn" :class="collapseIcon" @click="changeNavs"></span>
      </div>
      <div class="header-right">
        <span @click="exit">退出</span>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="asideWidth">
        <el-menu
          :default-active="activeIndex"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          style="border: 0;"
          :collapse="isCollapse"
          router
          >
          <el-menu-item index="/home">
            <i class="el-icon-s-platform"></i>
            <span slot="title">控制台</span>
          </el-menu-item>
          <el-menu-item index="/classify/find">
            <i class="el-icon-menu"></i>
            <span slot="title">分类管理</span>
          </el-menu-item>
          <el-submenu index="/goods">
            <template slot="title">
              <i class="el-icon-s-goods"></i>
              <span>商品管理</span>
            </template>
            <el-menu-item index="/goods/add">发布商品</el-menu-item>
            <el-menu-item index="/goods/find/1">在售商品</el-menu-item>
            <el-menu-item index="/goods/find/2">下架商品</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data(){
    return {
      isCollapse: false,
      asideWidth: '200px',
      collapseIcon: 'el-icon-s-fold',
      activeIndex: window.location.pathname
    }
  },
  methods: {
    changeNavs(){
      this.isCollapse = !this.isCollapse
      this.asideWidth = this.isCollapse ? '65px' : '200px'
      this.collapseIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    },
    exit(){
      localStorage.removeItem('token')
      this.$router.push({
        path: '/login'
      })
    }
  }
}
</script>

<style scoped>
.el-container{
  height: 100%;
}
.el-header{
  background-color: #545c64;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0px 20px;
  color: #fff;
}
.el-aside{
  background-color: #545c64;
  box-sizing: border-box;
  padding-top: 10px;
  transition: all 0.5s;
}
.header-title{
  font-size: 18px;
  font-weight: bold;
}
.header-left{
  display: flex;
  height: 100%;
  align-items: center;
}
.change-btn{
  margin-left: 10px;
  font-size: 22px;
  cursor: pointer;
}
.header-logo{
  font-size: 25px;
}
</style>